package com.example.administrator.spritelgs.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.administrator.spritelgs.R;
import com.example.administrator.spritelgs.bean.ChongZhiInfo;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/7/1.
 */

public class ChongZhiAdapter extends BaseAdapter {
    private Context context;
    private List<ChongZhiInfo> data;

    TextView tv_youhui;
    ImageView iv_image;
    ImageView iv_name;
    TextView tv_content;
    Button btn_price;

    public ChongZhiAdapter(Context context, List<ChongZhiInfo> data)
    {
        this.context = context;
        if(data != null){
            this.data = data;
        }
        else{
            data = new ArrayList<>();
        }
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
       if(convertView == null){
           convertView = View.inflate(context,R.layout.item_view_chonhzhilv,null);
       }
       //取出数据
        ChongZhiInfo bean = data.get(position);
        //取出单元格布局中的控件
        TextView tv_youhui = (TextView) convertView.findViewById(R.id.tv_youhui);
        ImageView iv_image = (ImageView)convertView.findViewById(R.id.iv_image);
        ImageView iv_name = (ImageView)convertView.findViewById(R.id.iv_name);
        TextView tv_content = (TextView)convertView.findViewById(R.id.tv_content);
        Button btn_price = (Button) convertView.findViewById(R.id.btn_price);

        tv_youhui.setText(bean.getYouhui());
        iv_image.setImageResource(bean.getImage());
        //iv_name
        tv_content.setText(bean.getContent());
        btn_price.setText(bean.getPriceStr());
        return convertView;
    }
}
